package top.beiermode.geektime.projects.user.web.controller;

import top.beiermode.geektime.projects.user.domain.User;
import top.beiermode.geektime.projects.user.service.UserService;
import top.beiermode.geektime.projects.user.service.UserServiceImpl;
import top.beiermode.geektime.web.mvc.controller.PageController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

/**
 * 用户注册
 *
 * @author Chen Song
 * @since
 */
@Path("/user/register")
public class UserRegisterController implements PageController {

    private final UserService userService = new UserServiceImpl();

    @POST
    public String execute(HttpServletRequest request, HttpServletResponse response) throws Throwable {
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        String email = request.getParameter("email");
        String phoneNumber = request.getParameter("phoneNumber");
        User user = new User();
        user.setName(name);
        user.setPassword(password);
        user.setEmail(email);
        user.setPhoneNumber(phoneNumber);

        userService.register(user);
        return "success.jsp";
    }

}
